﻿using BussinessObject.ObjectTwo;
using Class_Entity.ObjectTwo;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ProjectHK3.App_Code;

namespace ProjectHK3.Object_One
{
    public partial class FeePolicyDetail : System.Web.UI.Page
    {
        B_LoadDrop bl = new B_LoadDrop();
        B_Search bs = new B_Search();
        Delivery_free_polices dfp = new Delivery_free_polices();
        B_Update ab = new B_Update();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                load();
            }
        }
        public void load()
        {
            DropDownList1.DataSource = bl.service();
            DropDownList1.DataTextField = "SERVICE_NAME";
            DropDownList1.DataValueField = "SERVICE_ID";
            DropDownList1.DataBind();

            dfp = bs.loadFeePolicy(int.Parse(Session["Feepolicy"].ToString()));

           TextBox1.Text = dfp.DISTANCE_FROM.ToString();
           TextBox2.Text = dfp.DISTANCE_TO.ToString();
           TextBox3.Text = dfp.FEE_PER_KM.ToString();
           TextBox4.Text = dfp.WEIGHT_FROM.ToString();
           TextBox5.Text = dfp.WEIGHT_TO.ToString();
           TextBox6.Text = dfp.FEE_PER_KG.ToString();

           DropDownList1.SelectedValue = dfp.SERVICE_ID.ToString();

        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            dfp.SERVICE_ID = int.Parse(DropDownList1.SelectedValue.ToString());
            dfp.FEE_POLICY_ID = int.Parse(Session["Feepolicy"].ToString());
            dfp.DISTANCE_FROM =float.Parse (TextBox1.Text);
            dfp.DISTANCE_TO =float.Parse (TextBox2.Text);
            dfp.FEE_PER_KM =float.Parse (TextBox3.Text);
            dfp.WEIGHT_FROM= float.Parse (TextBox4.Text);
            dfp.WEIGHT_TO = float.Parse(TextBox5.Text);
            dfp.FEE_PER_KG = float.Parse (TextBox6.Text);
            dfp.FEE_POLICY_ID = int.Parse(Session["Feepolicy"].ToString());
            if (ab.UpdateFeePolicy(dfp) == true)
            {
                Alert.Show("Update Successful");
                load();
            }
            else
            {
                Alert.Show("false");
                load();
            }
            ;
        }

        protected void Button3_Click(object sender, EventArgs e)
        {
            DropDownList1.SelectedIndex = 0;
            TextBox1.Text = "";
            TextBox2.Text = "";
            TextBox3.Text = "";
            TextBox4.Text = "";
            TextBox5.Text = "";
            TextBox6.Text = "";
            TextBox1.Focus();
        }
    }
}